package NicknameInnerClassProject;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Menu {
    public static void main(String[] args) {
        // 1.窗口的设置
        JFrame window = new JFrame("登陆窗口");
        window.setSize(300,200);
        window.setLocationRelativeTo(null);  // 居中显示
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  // 设置关闭按钮影响窗口
        window.setVisible(true);

        // 2.设置面板以控制页面布局
        JPanel panel = new JPanel();
        window.add(panel);

        // 3.设置窗口的按钮
        JButton btn = new JButton("登陆");
        panel.add(btn);

        // 4.向按钮添加事件监听(接收监听对象)
        // btn.addActionListener(new ClickListener() );
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("点击了登陆按钮~~~");
            }
        });

        // 通过Lambda表达式完成按钮事件监听
        btn.addActionListener((e -> System.out.println("Hash manbo Dont speak")));

    }
}

class ClickListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("点击了登陆按钮");
    }
}
